
import 'package:flutter/material.dart';
import 'package:flutter_common/util/context_extension.dart';

import '../../../flutter_common.dart';

///只有单纯一行文字的可点击文本
class SingleListItem extends StatelessWidget {

  final Color textColor;
  final double? fontSize;
  final String text;
  final VoidCallback onTap;
  final double height;
  final bool showLine;
  final Widget? leading;
  final double lineLeftPadding;
  final double textLeftPadding;
  final Color? backgroundColor;
  final TextStyle? style;

  const SingleListItem(this.text,
      {Key? key, this.textColor = const Color(0xff333333),
        this.fontSize,
        this.leading,
        required this.onTap,
        this.showLine = false,
        this.backgroundColor,
        this.lineLeftPadding = 0,
        this.textLeftPadding = 15,
        this.height = 50,
        this.style,}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget body = Stack(
      alignment: Alignment.centerLeft,
      children: [
        if (leading != null) Positioned(left: textLeftPadding, child: leading!),
        Positioned(
            left: (leading == null ? 0 : 35) + textLeftPadding,
            child: Text(
              text,
              style: TextStyle(fontSize: fontSize??fontSize32, color: textColor).merge(style),
            )),
        const Positioned(
          right: 15,
          child: Icon(Icons.keyboard_arrow_right_outlined,
              color: Color(0xFFCCCCCC),size: 18,),
        ),
        if (showLine)
          Positioned(
            child: FxTheme().line,
            bottom: 0,
            left: lineLeftPadding,
            right: 0,
          )
      ],
    );
    body = Ink(
        height: height,
        width: double.infinity,
        color: backgroundColor,
        child: InkWell(onTap: () => throttle(onTap), child: body));
    return Material(color: Colors.transparent, child: body);
  }
}